import axios from 'axios';
import qs from 'qs';

export default class HTTP {
    aixosPost (options) {
      axios({
          url: options.url,
          method: 'post',
          //Credentials资质的意思,申请我请求数据时让我携带cookie去请求,(为后端能
          //给跨域浏览器设置cookie做铺垫,同时后端也要给它这个权限,也要相对应的设置,给了之后,后端就能给跨域浏览器设置cookie了)
          withCredentials: true, 
          header: {
             "Content-type": "application/x-www-form-urlencoded" 
          },
          data: qs.stringify(options.data)
      }).then(res => {
          options.success(res.data)
      }).catch(err => {
          options.error(err);
      })
    }

    axiosGet (options) {
        axios({
            url: options.url,
            method: 'get',
            withCredentials: true,
        }).then(res => {
            options.success(res.data);
        }).catch(err => {
            options.error(err);
        }); 
    }
}